package com.scut.edu.wanyou;

import java.util.List;

import com.scut.edu.wanyou.channel.Category;
import com.scut.edu.wanyou.search.SearchActivity;
import com.scut.edu.wanyou.widget.FlowIndicator;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class PublishActivity extends Activity implements OnClickListener{

	private TextView mTitleText = null;
	
	private EditText act_description = null; 
	
	private Spinner act_cats = null;
	
	private List<Category> categories = null;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_publish);
		categories = SearchActivity.categories;
		prepareView();
		mTitleText.setText("发布活动");
	}
	
	private void prepareView()
	{
		mTitleText = (TextView)findViewById(R.id.title_text);
		act_description = (EditText)findViewById(R.id.act_description);
		act_description.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				// TODO Auto-generated method stub
				Toast.makeText(getApplicationContext(), "Test", Toast.LENGTH_SHORT).show();
				return false;
			}
		});
		act_cats = (Spinner)findViewById(R.id.act_cat_spinner);
		act_cats.setAdapter(new CatsAdapter());
	}
	
	
	private class CatsAdapter extends BaseAdapter
	{

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return categories.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return categories.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			// TODO Auto-generated method stub
			if(arg1==null)
			{
				arg1 = LayoutInflater.from(getApplicationContext()).inflate(R.layout.cat_spinner_header, null);
			}else{
				ViewHolder holder;
				holder = (ViewHolder)arg1.getTag();
				if(holder==null)
				{
					holder = new ViewHolder();
					arg1 = LayoutInflater.from(getApplicationContext()).inflate(R.layout.cat_spinner_item, null);
					holder.text = (TextView)arg1.findViewById(R.id.spinner_item_text);
					arg1.setTag(holder);
				}else {
					holder = (ViewHolder)arg1.getTag();
				}
				holder.text.setText(categories.get(arg0-1).getCat_name());
			}
			return arg1;
		}
		
		private class ViewHolder
		{
			public TextView text;
		}
		
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {

		default:
			break;
		}
	}

}
